package com.itheima.controller;

import com.itheima.common.Result;
import com.itheima.pojo.Emp;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public Result<?> login(@RequestBody Emp emp) {
//        try {
//            String token = empService.login(emp);
//            return Result.success(token);
//        } catch (Exception e) {
//            log.error(e.getMessage(), e);
//            return Result.error(e.getMessage());
//        }
        String token = empService.login(emp);
        return Result.success(token);
    }

}
